package com.longge;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class UncommonFromSentences {

    public String[] uncommonFromSentences(String s1, String s2) {
        String[] s1Arr = s1.split(" ");
        String[] s2Arr = s2.split(" ");

        Map<String, Integer> map = new HashMap<>();

        for (String str : s1Arr) {
            Integer count = map.getOrDefault(str, 0);
            map.put(str, count + 1);
        }
        for (String str : s2Arr) {
            Integer count = map.getOrDefault(str, 0);
            map.put(str, count + 1);
        }
        Set<String> set = new HashSet<>();
        map.forEach((k, v) -> {
            if (v == 1) {
                set.add(k);
            }
        });

        return set.toArray(new String[0]);
    }
}
